package com.linkstec.neo4j;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.neo4j.driver.v1.AuthTokens;
import org.neo4j.driver.v1.Driver;
import org.neo4j.driver.v1.GraphDatabase;
import org.neo4j.driver.v1.Record;
import org.neo4j.driver.v1.Session;
import org.neo4j.driver.v1.StatementResult;
import static org.neo4j.driver.v1.Values.parameters;

public class Neo4jTest {
	private static final Logger logger = LogManager.getLogger();

	public static void main(String[] args) {
		logger.info("neo4j!!!");
		 Driver driver = GraphDatabase.driver( "bolt://localhost:7687", AuthTokens.basic( "neo4j", "admin" ));
	        Session session = driver.session();
	        session.run( "CREATE (a:ren {name: {name}, title: {title}})",
	                parameters( "name", "Arthur001", "title", "King001" ) );

	        StatementResult result = session.run( "MATCH (a:ren) WHERE a.name = {name} " +
	                                              "RETURN a.name AS name, a.title AS title",
	                parameters( "name", "Arthur001" ) );
	        while ( result.hasNext() )
	        {
	            Record record = result.next();
	            logger.info( record.get( "title" ).asString() + " " + record.get( "name" ).asString() );
	        }
	        session.close();
	        driver.close();


	}

}
